package com.jae.service.impl;


import com.jae.mapper.RescMapper;
import com.jae.model.resc.Resc;
import com.jae.model.resc.RescDTO;
import com.jae.model.user.User;
import com.jae.service.RescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RescServiceImpl extends BaseServiceImpl implements RescService {

	@Autowired
	private RescMapper rescMapper;
	

	/**
	* 	获取所有权限	
	*/
	@Override
	public List<Resc> findAll() {
		return rescMapper.findAll();
	}
	
	/**
	* 	获取一条权限	
	*/
	@Override
	public RescDTO findOne(Map map) {
		return rescMapper.findOne(map);
	}
	
	/**
	* 	根据ID获取权限	
	*/
	@Override
	public RescDTO findById(Long resc_id) {
		Resc resc = new Resc();
		resc.setResc_id(resc_id);
	
		return rescMapper.findById(resc);
	}
	
	
	
	/**
	 * 新增权限
	 */
	@Override
	public boolean insert(Resc resc, User user){
		if(rescMapper.insert(resc)!=1)
			serviceError("插入失败");
		return true;
	}
	
	/**
	 * 修改权限
	 */
	@Override
	public boolean update(Resc resc, User user){
		if(rescMapper.update(resc)!=1)
			serviceError("修改失败");
		return true;
	}
	
	
	/**
	 * 	逻辑删除权限
	 */
	@Override
	public boolean updateDelete(Long resc_id, User user){
		Resc old=new Resc();
		//resc.setLast_updated_by(user.getUser_id());
		//resc.setLast_updated_date(new Date());
		old.setResc_id(resc_id);
		
		if(rescMapper.updateDelete(old)!=1)
			serviceError("逻辑删除失败");
		return true;
	}
	
	/**
	 * 	物理删除权限
	 */
	@Override
	public boolean delete(Long resc_id){
		Resc old = new Resc();
		old.setResc_id(resc_id);
		if(rescMapper.delete(old)!=1)
			serviceError("删除失败");
		return true;
	}
	
}